package rdgest.database;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;

public class Table {

	private String tableName = null;

	// private Vector fields = null;
	private Hashtable fields = null;

	public Table(String tableName) {
		this.tableName = tableName;
		this.fields = new Hashtable();
	}

	public Table(String tableName, Hashtable fields) {
		this.tableName = tableName;
		this.fields = fields;
	}

	public void addField(String fieldName) {
		addField(fieldName, null);
	}

	public void addField(String fieldName, String fieldValue) {
		this.fields.put(fieldName, fieldValue);
	}

	public String getTableName() {
		return this.tableName;
	}

	public String getUpdateSet() {
		String updateSet = "";
		Iterator fieldIterator = this.fields.entrySet().iterator();
		while (fieldIterator.hasNext()) {
			Map.Entry entry = (Map.Entry) fieldIterator.next();
			updateSet = updateSet.concat((String)entry.getKey()+"="+(String)entry.getValue());
			if(fieldIterator.hasNext()) updateSet = updateSet.concat(",");
		}
		return updateSet;
	}
	public String getInsertValuesSet(){
		String valueSet = "";
		Iterator fieldIterator = this.fields.entrySet().iterator();
		while (fieldIterator.hasNext()) {
			Map.Entry entry = (Map.Entry) fieldIterator.next();
			valueSet = valueSet.concat("'"+(String)entry.getValue()+"'");
			if(fieldIterator.hasNext()) valueSet = valueSet.concat(",");
		}
		return valueSet;
		
	}

	public String toString() {
		String concatFields = "";
		for (int index = 0; index < this.fields.size(); index++) {
			//concatFields = concatFields.concat((String) this.fields.get(index));
			if (index != fields.size() - 1)
				concatFields = concatFields.concat(",");
		}
		return concatFields;
	}
}
